package com.sql_sys;

import java.sql.SQLException;
import java.util.* ;

public class App 
{

    public static void Init_menu ()
    {

        System.out.println () ;

        System.out.println ("学生管理系统") ;

        System.out.println ("1.登录") ;

        System.out.println ("2.退出") ;

    }

    public static int stumenu (Scanner input)
    {

        System.out.println () ;

        System.out.println ("1.增加数据") ;

        System.out.println ("2.删除数据") ;

        System.out.println ("3.查找数据") ;

        System.out.println ("4.修改数据") ;

        System.out.println ("0.程序退出") ;

        System.out.printf ("请选择: ") ;

        int ret = input.nextInt () ;

        return ret ;

    }

    public static void studen_sys (Scanner input) throws ClassNotFoundException, SQLException
    {

        System.out.printf ("请输入账号: ") ;

        String username = input.nextLine () ;

        System.out.printf ("请输入密码: ") ;

        String password = input.nextLine () ;

        System.out.println () ;

        load_sys sql = new load_sys(username, password) ;

        int r ;

        while ((r = stumenu(input)) != 0) 
        {

            switch (r) 
            {

                case 1 :
                    
                    break ;

                case 2 :

                    System.out.println ("删除数据!") ;

                    sql.erase (input) ;

                    break ;

                case 3 :

                    break ;

                case 4 :

                    System.out.println ("修改数据!") ;

                    sql.update (input) ;

                    break ;
            
                default :

                    System.out.println ("字符非法,请重新输入!") ;

                    break ;

            }
            
        }

    }
    
    public static void main( String[] args ) throws ClassNotFoundException, SQLException
    {
    
        Scanner input = new Scanner(System.in , "GBK") ;

        while (true)
        {

            Init_menu () ;

            System.out.printf ("请输入: ") ;

            int in = input.nextInt () ;

            switch (in) 
            {

                case 1:

                    input.nextLine () ;

                    studen_sys (input) ;

                    break ;

                case 2:

                    System.out.println ("退出!") ;

                    break ;
            
                default:

                    System.out.println ("非法字符,请重新输入!") ;

                    break ;

            }

            if (in == 2)
            {

                break ;

            }
             
        }

        input.close () ;
        
    }

}